package com.jacky.myVolatile;

public class volatileTest {
    private static int times = 0;
    int a = 1;
    boolean status = false;
    public void changeStatus(){
        a = 10;
        status = true;
    }
    public void run(){
        if (status){
            int b = a + 1;
            System.out.println(Thread.currentThread().getName()+":"+b);
        }
    }

    public static void main(String[] args) {
        volatileTest test = new volatileTest();
        while (times<=100) {
            times++;
            new Thread() {
                @Override
                public void run() {
                    test.changeStatus();
                }
            }.start();
            new Thread() {
                @Override
                public void run() {
                    test.run();
                }
            }.start();
        }
    }
}
